package com.xb.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xb.model.domain.Users;
import com.xb.system.mapper.DistinctUserMapper;
import com.xb.system.mapper.UsersMapper;
import com.xb.system.service.UsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (Users)表服务实现类
 */
@Service
@Slf4j
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {
    @Resource
    private UsersMapper usersMapper;
    
    @Resource
    private DistinctUserMapper distinctUserMapper;

    public boolean checkUserMatch(String phone, String username) {
        //先去分表中查询，查不到再去distinct_user表中查询
        if (usersMapper.checkUserMatch(phone, username) > 0) {
            return true;
        } else return distinctUserMapper.checkUserMatch(phone, username) > 0;
    }
    
    public void createIndexes() {
        log.info("正在创建分表的索引");
        usersMapper.createIndexes();
        log.info("创建分表索引成功，正在创建distinct_user表的索引");
        distinctUserMapper.createIndexes();
        log.info("索引创建成功");
    }
    
    public void dropIndexes() {
        usersMapper.dropIndexes();
        log.info("删除分表索引成功，正在删除distinct_user表的索引");
        distinctUserMapper.dropIndexes();
        log.info("索引删除成功");
    }
}

